<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script type="text/javascript">
		window.onload=function(){

			var oTxt = document.getElementById('txt1');
			oTxt.onkeydown=function(ev){
                var oEvent=ev||event;
                alert(oEvent.keyCode);
                //0==96  48
                //9==105 57
                if (oEvent.keyCode!=8 && (oEvent.keyCode<48 || oEvent.keyCode>57))  {
                	return false;
                };

			};

		};
	</script>
</head>
<body>
	<input type="text" id="txt1">
</body>
</html>